/*
 * Copyright 2010. 
 * 
 * This document may not be reproduced, distributed or used 
 * in any manner whatsoever without the expressed written 
 * permission of xrkol Corp. 
 * 
 * $Rev: Rev $
 * $Author: Author $
 * $LastChangedDate: LastChangedDate $
 *
 */

package com.xrkol.sharelib.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.xrkol.sharelib.dao.ClassDao;
import com.xrkol.sharelib.entity.Clazz;
import com.xrkol.sharelib.entity.Teacher;

/**
 * @author peng.xia
 * 
 */
@Repository
public class ClassDaoImpl extends BaseDaoImpl<Clazz, String> implements ClassDao {

    @Override
    public List<Clazz> getClassesByAdviser(Teacher currentUser) {
        String queryString = "from Clazz c where c.adviser=?";
        return executeQueryWithoutPaging(queryString, currentUser);
    }

    @Override
    public List<Clazz> getAllClasses(String schoolId) {
        String queryString = "from Clazz c where c.schoolId=? order by c.createTime desc";
        return executeQueryWithoutPaging(queryString, schoolId);
    }

    @Override
    public List<Clazz> findClassesWithPagination(String schoolId, Integer page) {
        String queryString = "from Clazz c where c.schoolId=?";
        return executeQueryWithPagination(queryString, " order by id desc", page, schoolId);
    }

    @Override
    public Clazz findClassByAdviser(Teacher currentTeacher) {
        String queryString = "from Clazz c where c.adviser=?";
        List<Clazz> clazzs = executeQueryWithoutPaging(queryString, currentTeacher);
        return clazzs.isEmpty() ? null : clazzs.get(0);
    }

    @Override
    public boolean checkExist(String className, String schoolId) {
        String queryString = "from Clazz c where c.className=? and c.schoolId=?";
        List<Clazz> clazzs = executeQueryWithoutPaging(queryString, className, schoolId);
        return clazzs.isEmpty() ? false : true;
    }

}
